package gameobj;

import java.util.Random;

import manager.ElementManager;
import manager.LevelManager;

public class Enemy extends Actor {
	private static ElementManager em = null;
	
	public Enemy() {
		super();
		this.setMaxHealth(1);
		this.setHealth(1);
		this.setDirection(false);
		this.setSpeed(3);
		if (em == null) {
			em = ElementManager.get();
		}
		this.setAttacking(true);
		this.setAttackSpeed(40);
	}

	@Override
	protected void attack() {
		Bullet bullet = new Bullet();
		bullet.setX(getX());
		bullet.setY(getY());
		bullet.setH(50);
		bullet.setW(50);
		bullet.setSpeed(5);
		bullet.setPlayerOwned(false);
		bullet.setModel(bulletModel);
		bullet.setAttack(5);
//		添加进管理
		em.add(ElementType.ITEM, bullet);

	}

	@Override
	public void getHurt(int damage) {
		this.setHealth(getHealth()-damage);
		if(this.getHealth()<=0)
		{
			this.setHealth(0);
			this.death();
		}
	}

	public void death() {
		// TODO Auto-generated method stub
		System.out.println("敌人死亡");
		this.setAlive(false);
		
//		随机掉落
		Random rd = new Random();
		int rdNum = rd.nextInt(10);
		if (rdNum > 7) {
			Prop.newProp(getX(), getY());
		}
		
		LevelManager lm = LevelManager.get();
		lm.scoreUp(50);
	}
}
